def write_file():
    file = None
    try:
        file = open("hiahia.txt", "r")
        a=10
        b = 2
        rst = a / b 
        arr = [2,3]
        val = arr[5]
        file.write(f"hahahaha:{rst}")
    except ZeroDivisionError as e:
        print("出现除零异常：",e,type(e))
    except PermissionError as e:
        print("出现权限异常：",e,type(e))
    except IndexError as e:
        print("索引异常：",e,type(e))
    except Exception as e:
        print("出现未知异常：",e,type(e))
    finally:
        if file is not None:
            file.close()
            print("关闭资源")
write_file()
           